package com.model.rule;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.edu.hfut.dmic.webcollector.crawler.Crawler;

import com.vs.crawl.news.WriteCrawler;

import constant.XmlElementCoonstant;


/**
 * *********************************************
 * @author Administrator
 * @FileName WriteFileRool.java
 * @Description 写入规则(根据size写入)
 **********************************************
 */
public class WriteFileRuleListSize extends FileRule{
	public static final Logger LOG = LoggerFactory.getLogger(WriteFileRuleListSize.class);
	
	public WriteFileRuleListSize() {
		super();
	}

	@Override
	public void executeFileRule() {
		WriteCrawler writeCrawler = this.getWriteCrawler();
		Crawler crawler = writeCrawler.getCrawler();
		
		long size;
		String value = super.getValue();
		if(value == null || value.equals("")){
			size = XmlElementCoonstant.DEFAULT_SIZE;
		}else{
			size = Long.valueOf(value);
			if(size <= 0){
				size = XmlElementCoonstant.DEFAULT_SIZE;
			}
		}
		LOG.info("WriteFileRuleListSizeThread->size->" + crawler.getTotalSize() + "----------size->" + size);
		
		if(crawler.getTotalSize().get() >= size){
			writeCrawler.writeData();
		}
	}
	

}
